#ifndef ASYNC_QUEUE_H_
#define ASYNC_QUEUE_H_
#include "job.h"

#include <queue>
template <class T>
class AsyncQueue {
private:
	std::queue<T> m_queue;
	Mutex _queue_mutex;
	Semaphore _sem;

	AsyncQueue(AsyncQueue&);
public:
	
	AsyncQueue(){
	}
	~AsyncQueue(){}
	void enqueue(T job) {
		_queue_mutex.lock();
		m_queue.push(job);
		_queue_mutex.unlock();
		_sem.V();
	}

	T dequeue(long timeout = 0){
		T e;
		_sem.P();
		_queue_mutex.lock();
		if (m_queue.size() == 0)
			e = NULL;
		else{
			e = m_queue.front();
			m_queue.pop();
		}
		_queue_mutex.unlock();
		return e;
			
	}
	
};
#endif
